<?php
/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑       永不宕机     永无BUG
 */
/*
 * 职位操作页
 * @Author: htong
 * @Date: 2021-03-02 18:16:55
 * @LastEditors: htong
 * @LastEditTime: 2021-03-02 18:39:06
 * @Description: file content
 * @FilePath: \gongchengqiaojob\Application\Home\Controller\PcConsoleapiController.class.php
 */
namespace Home\Controller;
use Common\Controller\PcApiController;
use Common\ORG\PublicFunction;
use Common\ORG\WxFunction;
use Think\Db;

class PcConsoleapiController extends PcApiController{
	
	public function _initialize() {

        $getsecret  = $_SERVER['HTTP_APPSECRET'];
        //取head标签内容
        if(!preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/', $getsecret) && ACTION_NAME<>'getUserInfo'){
            $this->ajaxReturn(1, 'appsecret格式错误');
        }

        if($this->appsecret <> $getsecret && ACTION_NAME<>'getUserInfo'){
            $this->ajaxReturn(1, 'appsecret错误');
        }
        parent::_initialize();
    }
    /**
     * 基本信息
     */
	public function essentialInformation(){
        $company_profile = D('CompanyProfile')->field('logo,companyname,district_cn,nature_cn,address,scale_cn,register_date,certificate_img,short_desc')->where(array('uid'=> $this->userinfo['uid']))->find();
        $company_profile['logo'] = attach($company_profile['logo'],'company_logo');
        $company_profile['certificate_img'] = attach($company_profile['certificate_img'],'certificate_img');
        $this->ajaxReturn(0, 'ok', $company_profile);
    }

    /**
     * 账户安全
     */
    public function accountSecurity(){
        $user = M('members')->field('mobile,email')->where(['utype'=>1,'uid'=>$this->userinfo['uid']])->find();
        $members_bind = M('members_bind')->field('info')->where(['uid'=>$this->userinfo['uid']])->find();
        $info = json_decode($members_bind['info'],true);
        $data = array();
        $data['mobile'] = $user['mobile'];
        $data['email'] = $user['email'];
        $data['nickName'] = $info['wxdata']['nickName'];
        $this->ajaxReturn(0, 'ok', $data);
    }
    /**
     * 我的工程币
     */
    public function currency(){
        $page = I('page',1);
        $pagesize = I('pagesize',10);
        $MembersSetgcb = M('MembersSetgcb')->field('all_num,use_num,setmeal_name')->where(array('uid' => $this->userinfo['uid']))->find();
        $surplus = $MembersSetgcb['all_num']-$MembersSetgcb['use_num'];
        $surplus = $surplus>=10000 ? $surplus/10000 .'w' : $surplus;
        $firstday = date('Y-m-01 00:00:00');
        $lastday = date('Y-m-d 23:59:59');
        $where = [];
        $where['add_time'] = [['elt',$firstday],['egt',$lastday]];
        $where['uid']= ['eq',$this->userinfo['uid']];
        $where2 = [];
        $where2['use_type']= ['eq','gcb'];
        $where2['order_type']= ['eq','buy_gcb'];
        $where3 = [];
        $where3['use_type']= ['eq','gcb'];
        $where3['order_type']= ['not in',['buy_gcb']];
        $priceadd = M('member_use_log')->where($where)->where($where2)->sum('price');
        $pricepay = M('member_use_log')->where($where)->where($where3)->sum('price');
        $log_list =  M('member_use_log')->field('price,desc,add_time,order_type')->where(['use_type'=>'gcb','uid' => $this->userinfo['uid']])->page($page,$pagesize)->select();
        
        $data = [];
        $data['surplus'] = $surplus;
        $data['priceadd'] = $priceadd?$priceadd:0;
        $data['pricepay'] = $pricepay?$pricepay:0;
        $data['log_list'] = $log_list;
        $this->ajaxReturn(0, 'ok', $data);
    
    }
    /**
     * 我的套餐
     */
    public function mySetMeal(){
        $MembersSettaocan = M('MembersSettaocan')->where(array('uid'=>$this->userinfo['uid']))->find();
        $data = [];
        $data['has_taocan']=0;
        if($MembersSettaocan){
        $data['has_taocan']=1;
        }
        $data['start_time'] =  date('Y-m-d',$MembersSettaocan['add_time']);
        $data['end_time'] =  $MembersSettaocan['end_time']?date('Y-m-d',$MembersSettaocan['end_time']):'';
        $data['jl_down_num'] =  $MembersSettaocan['jl_down_num'];
        $data['jl_down_surplus'] =  $MembersSettaocan['jl_down_num']- $MembersSettaocan['jl_yi_down_num'];
        $data['duan_qi_fa_count'] =  $MembersSettaocan['duan_qi_fa_count'];
        $data['duan_qi_fa_surplus'] =  $MembersSettaocan['duan_qi_fa_count']- $MembersSettaocan['duan_qi_yi_fa_count'];;
        $data['xmzc_fa_count'] =  $MembersSettaocan['xmzc_fa_count'];
        $data['xmzc_fa_surplus'] =  $MembersSettaocan['xmzc_fa_count']- $MembersSettaocan['xmzc_yi_fa_count'];;
        $data['ji_zhao_fa_count'] =  $MembersSettaocan['ji_zhao_fa_count'];
        $data['ji_zhao_fa_surplus'] =  $MembersSettaocan['ji_zhao_fa_count']- $MembersSettaocan['ji_zhao_yi_fa_count'];;
        $data['cg_fa_count'] =  $MembersSettaocan['cg_fa_count'];
        $data['cg_yi_fa_surplus'] =  $MembersSettaocan['cg_fa_count']- $MembersSettaocan['cg_yi_fa_count'];;
        
        $this->ajaxReturn(0, 'ok', $data);
        
    }

    /**
     * 消费记录
     */
    public function payIog(){
        $page =I('page',1);
        $pagesize =I('pagesize',1);
        $where['use_type']= ['eq','gcb'];
        $where['order_type']= ['not in',['buy_gcb']];
        $where['uid']= ['eq',$this->userinfo['uid']];
        $log_list =  M('member_use_log')->field('price,desc,add_time')->where($where)->page($page,$pagesize)->select();
        $this->ajaxReturn(0, 'ok', $log_list);
    }

       /**

     * agreement

     * 服务条款

     * 工程桥注册服务条款

     * @access public

     * @since

     * @return json

     */
    public function agreement(){
        $agreement = M('Text')->where(array('name'=>'agreement'))->find();

        $this->ajaxReturn(0, 'ok', ['text'=>!empty($agreement['value']) ? $agreement['value']:'']);

    }


    /**
     * conceal
     * 隐私协议
     * 工程桥注册隐私协议
     * @access public
     * @since
     * @return json
     */
    public function conceal(){
        $agreement = M('Text')->where(array('name'=>'conceal'))->find();

        $this->ajaxReturn(0, 'ok', ['text'=>!empty($agreement['value']) ? $agreement['value']:'']);
    }

    /**
     * conceal
     *风险提示与责任声明
     * 
     * @access public
     * @since
     * @return json
     */
    public function risk(){
        $agreement = M('Text')->where(array('name'=>'risk'))->find();

        $this->ajaxReturn(0, 'ok', ['text'=>!empty($agreement['value']) ? $agreement['value']:'']);
    }
    

    
}
?>